from django.contrib import admin
from .models import AnsibleInventory, AnsibleCredential, AnsiblePlaybook, AnsibleJob


@admin.register(AnsibleInventory)
class AnsibleInventoryAdmin(admin.ModelAdmin):
    list_display = ['name', 'created_by', 'created_at']
    search_fields = ['name', 'description']
    filter_horizontal = ['hosts']


@admin.register(AnsibleCredential)
class AnsibleCredentialAdmin(admin.ModelAdmin):
    list_display = ['name', 'credential_type', 'username', 'created_by', 'created_at']
    search_fields = ['name', 'username']
    list_filter = ['credential_type']


@admin.register(AnsiblePlaybook)
class AnsiblePlaybookAdmin(admin.ModelAdmin):
    list_display = ['name', 'status', 'inventory', 'credential', 'created_by', 'created_at']
    search_fields = ['name', 'description']
    list_filter = ['status']


@admin.register(AnsibleJob)
class AnsibleJobAdmin(admin.ModelAdmin):
    list_display = ['id', 'job_type', 'status', 'created_by', 'created_at']
    list_filter = ['job_type', 'status']
    readonly_fields = ['result', 'stdout', 'stderr', 'start_time', 'end_time']
